<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>websocket</title>
</head>
<script>
    var ws = new WebSocket("wss://localhost:8888/websocket");
ws.onopen = function() {
   //ws.send("Hello, world");
};
ws.onmessage = function (evt) {
   //alert(evt.data);
  var innerHTML = document.querySelector("#content").innerHTML
  document.querySelector("#content").innerHTML  += evt.data +"<br/>"
};
function send(){
 ws.send(document.querySelector("#text").value)
}

</script>
<body>
<input id="text" type="text">
<button onclick="send()">发送</button>
<div id="content"></div>
</body>
</html>